/**
 * 
 */
package com.couponornot.social.txwb.api;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.InputStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;

import com.couponornot.social.txwb.api.json.TxwbObjectMapper;

/**
 * @author iday
 * 
 */
public class TxwbProfileTestCase {
	MappingJacksonHttpMessageConverter converter;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		converter = new MappingJacksonHttpMessageConverter();
		converter.setObjectMapper(new TxwbObjectMapper());
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		converter = null;
	}

	@Test
	public void testTxwbProfile() {
		try {
			TxwbProfile txwb = (TxwbProfile) converter.read(TxwbProfile.class,
					new HttpInputMessage() {

						@Override
						public HttpHeaders getHeaders() {
							return null;
						}

						@Override
						public InputStream getBody() throws IOException {
							return this.getClass().getResourceAsStream(
									"/user.json");
						}
					});
			assertEquals("B624064BA065E01CB73F835017FE96FA", txwb.getOpenId());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Test(expected = RuntimeException.class)
	public void testTxwbProfileException() {
		try {
			converter.read(TxwbProfile.class, new HttpInputMessage() {

				@Override
				public HttpHeaders getHeaders() {
					return null;
				}

				@Override
				public InputStream getBody() throws IOException {
					return this.getClass().getResourceAsStream(
							"/user-error.json");
				}
			});
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
